<?php
/**
 * Created by PhpStorm.
 * User: jinjb
 * Date: 2015/5/9
 * Time: 11:27
 */

namespace business\base\models;

use yii\db\Query;

/**
 * Class BasicCategoryModel
 * @package business\base\models
 * @property string categoryId
 * @property string categoryShortName
 * @property string categoryName
 * @property string categoryCode
 * @property string creationTime
 * @property string lastModifiedTime
 * @property string isLeaf
 * @property string hierarchyLevel
 * @property string categoryStatus
 * @property string operator
 * @property string displayOrder
 * @property string parentCode
 *
 */
class BasicCategoryModel extends BaseActiveRecord
{
    const VALID = 1;           //启用
    const INVALID = 0;         //停用

    public static function tableName()
    {
        return 'b2b_parameter.bsp_basic_forest';
    }

    public $_fieldsAlias = [
        'categoryId' => 'category_id',
        'categoryShortName' => 'category_shortname',
        'categoryName' => 'category_name',
        'categoryCode' => 'category_code',
        'parentCode' => 'parent_code',
        'creationTime' => 'creation_time',
        'lastModifiedTime' => 'last_modified_time',
        'isLeaf' => 'is_leaf',
        'hierarchyLevel' => 'hierarchy_level',
        'categoryStatus' => 'category_status',
        'operator' => 'operator',
        'displayOrder' => 'display_order',
    ];

    public function getCategoryInfo($conditions = [], $fields = "*", $orderBy = false, $limit = 0)
    {
        $query = (new Query())
            ->from('b2b_parameter.bsp_basic_forest')
            ->where($conditions)
            ->select($fields);
        if($orderBy){
            $query->orderBy('display_order desc')
                ->limit($limit);
        }

        return $query->createCommand(\Yii::$app->db)
            ->queryAll();
    }
}
